/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package consecutive;

import java.util.ArrayList;
import rule.Rule;
import score.Score;

/**
 *
 * @author Daniel Gribel
 */
public abstract class Consecutive extends Rule {
    
    private boolean clauseResult;
    
    public Consecutive(Score score, String name) {
        super(score, name);
    }
    
    @Override
    public void checkConditions(String dataEntry) {
        setCounter(0);
        ArrayList<Integer> positions = new ArrayList<Integer>();
        for(int i = 0; i < dataEntry.length(); i++) {
            checkClauses(dataEntry.charAt(i));
            if(this.clauseResult)
                positions.add(i);
        }
        
        int counter = 0;
        if(positions.size() == 1)
            counter = 1;
        
        if(positions.size() > 1) {
            for(int i = 0; i < positions.size(); i++) {
                if(i < positions.size() - 1) {
                    if(positions.get(i) == positions.get(i+1) - 1)
                        counter++;
                }
                else {
                    if(positions.get(i-1) == positions.get(i) - 1)
                        counter++;
                }
            }
        }
        
        this.setCounter( (-1) * counter);
    }
    
    @Override
    public abstract void checkClauses(char character);
    
    public void setClauseResult(boolean clauseResult) {
        this.clauseResult = clauseResult;
    }
    
    public boolean isClauseResult() {
        return clauseResult;
    }

}
